home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / CMaster Demo v2.0.3 / CMaster XTRN Projects / mainXTRNdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-12  |  4.9 KB  |  181 lines  |  [TEXT/KAHL]

  1. /*
  2.  *
  3.  *            mainXTRNdemo.c:    demo version of an external code resource
  4.  *            © 1994 Jersey Scientific, All Rights Reserved
  5.  *
  6.  *            Notes:
  7.  *                Use SetupA4 if you want to use globals in your program. However,
  8.  *                after you do a "merge" or rebuild of your external, the new
  9.  *                code resource that loads will have null globals. 
  10.  *            History:
  11.  *                01/01/94: Version 1 of xtern structure
  12.  *                06/05/94: More stuff
  13.  */
  14.  
  15. #include <SetUpA4.h>
  16. //#include "CallKeyEquivalents.h"
  17. //#include "CallKeyFunctions.h"
  18. #include "XTRN.h"
  19.  
  20.     Boolean
  21. main(
  22.     short            type,    // type of call (XTRN_xxxx, see above)
  23.     XtrnPtr            xP,     // xtern structure
  24.     XtItemPtr        iP,        // some fields are for your private use - see above
  25.     short            keys    // modifier keys associated with this event (KEY, MENU, and ZOOM only)
  26.                             // - or the event return code
  27. ) {
  28.     char            *fp;
  29.     unsigned char    len, j; 
  30.     long            start, end;
  31.     Handle            h;
  32.     Str255            foop;
  33.     TextDataPtr        tdP;
  34.     Boolean            retCode;
  35.  
  36.     RememberA0();
  37.     SetUpA4();
  38.  
  39.     retCode = FALSE;        // default return value
  40.  
  41.     // decide what to do based on the action
  42.     switch(type) {
  43.     case XTRN_INIT:
  44.         // better to not call CMaster callbacks here
  45.             // maybe allocate some free memory
  46.             //iP->reserved0 = (long)NewHandleClear(256);
  47.             //if(iP->reserved0 == 0)
  48.             //    (*xP->debugPrintf)("NO MEMORY!!!");
  49.         // maybe get a preference resource
  50.         //iP->reserved1 = (long)GetResource('PREF', resID);
  51.         
  52.         iP->wantRawEvents = TRUE;
  53.         goto ret;                                        // any value OK
  54.  
  55.     case XTRN_QUIT:
  56.         // better to not call CMaster callbacks here
  57.             //if(iP->reserved0 != 0)
  58.             //    DisposeHandle((Handle)iP->reserved0);
  59.         goto ret;                                        // any value OK
  60.  
  61.     case XTRN_RAW:
  62.     case XTRN_COOKED:
  63.         // only should get these if you set the xP->... parameter to !FALSE
  64.  
  65.         // if testing for the first time, you might want to add this line so that
  66.         // - your action only takes effect if the CAPSLOCK key is depressed. Then,
  67.         // - if you have a coding bug you won't have to go to great lengths to get
  68.         // - THINK sane if you have a bug and eat all events, etc...
  69.         if(CAPSLOCK){
  70.             short mods, key;
  71.             if(xP->evp->what == keyDown) {
  72.                 mods = xP->evp->modifiers & (cmdKey|optionKey|controlKey|shiftKey);
  73.                 key = xP->evp->message & charCodeMask;
  74.                 if(mods == 0 && (key == 'X' || key == 'x'))
  75.                     SysBeep(1);
  76.             }
  77.         }
  78.         // your code goes here
  79.         // ...
  80.         retCode = (Boolean)keys;                        // return what was passed to us
  81.         goto ret;                                        // any value OK
  82.  
  83.     case XTRN_WIND_OPEN1_SIZE:
  84.     case XTRN_WIND_OPEN2_DATA:
  85.         SysBeep(1);
  86.         // only should get these if you set the xP->... parameter to !FALSE
  87.         // use getTextData() to get file info on current window (so you could
  88.         // - open the resource fork of the file if necessary
  89.         goto ret;                                        // any value OK
  90.  
  91.     case XTRN_WIND_CLOSE:
  92.         SysBeep(1);
  93.         // only should get these if you set the xP->... parameter to !FALSE
  94.         // use getTextData() to get file info on current window (so you could
  95.         // - open the resource fork of the file if necessary
  96.         goto ret;                                    
  97.  
  98.     case XTRN_KEY:
  99.     case XTRN_MENU:
  100.         break;                                            // handle below
  101.  
  102.     case XTRN_ZOOM:
  103.         // change the userState or stdState rects in the window->dataHandle
  104.         // return 0, inZoomIn, or inZoomOut (from windows.h)
  105.         // 0 sayslet whatever would have happened, happen
  106.         // inZoomIn and inZoomOut tell CMaster where to zoom the window
  107.         goto ret;                                        // any value OK
  108.     }
  109.  
  110.     // now, look at the key modifiers
  111.     switch(keys) {
  112.     case 0:
  113. #ifdef Get_All_Files_And_Show_Them
  114.         {
  115.             FSSpec     *fsspP;
  116.             short     xxx;
  117.             Str255    str;
  118.             Boolean    ret;
  119.     
  120.             ret = (*xP->getFiles)(xP->window, FILES_HEADER, &fsspP, &xxx);
  121.             str[0] = (*xP->sprintf)((char *)&str[1], "Ret was %d num %d", ret, xxx);
  122.             ParamText(str, str, str, str);
  123.             (*xP->positionSubDialog)('ALRT', xP->resID);
  124.             NoteAlert(xP->resID, (void *)0);
  125.         }
  126. #endif
  127.         SysBeep(1);
  128.         break;
  129.     case (optionKey):
  130.         (*xP->softBeep)();
  131.         break;
  132.     case (cmdKey):
  133.         (*xP->hardBeep)();
  134.         break;
  135.     case (controlKey):
  136.         (*xP->doneBeep)();
  137.         break;
  138.     case (shiftKey):
  139.         tdP = (*xP->getTextData)(xP->window);
  140.         if(tdP != (void *)0) {
  141.             start    = tdP->startSelect;
  142.             end        = tdP->endSelect;
  143.             h        = tdP->text;
  144.  
  145.             len = end - start;
  146.             if(len == 0) {
  147.                 SysBeep(1);
  148.                 goto ret;                                        // any value OK
  149.             }
  150.             fp = *h + start;
  151.             for(foop[0]=len, j=0; len--; )
  152.                 foop[++j] = *fp++;
  153.             
  154.             ResetAlrtStage();
  155.             ParamText(foop, foop, foop, foop);
  156.             (*xP->positionSubDialog)('ALRT', xP->resID);
  157.             NoteAlert(xP->resID, (void *)0);
  158.             DisposePtr((Ptr)tdP);
  159.         }
  160.         break;
  161.     case (shiftKey|optionKey):
  162.         break;
  163.     case (shiftKey|cmdKey):
  164.         break;
  165.     case (optionKey|cmdKey):
  166.         break;
  167.     case (optionKey|controlKey):
  168.         break;
  169.     case (optionKey|shiftKey|cmdKey):
  170.         // supposed you changed your PREF resource here
  171.         // ChangeResource('PREF', resID);
  172.         // UpdateResFile(xP->xtrnResFile);
  173.         break;
  174.     }
  175.     
  176.     // return FALSE to effectively "eat" the event. If you changed the event
  177.     // - (say a NULLEVENT to something else), then return TRUE.
  178.   ret:
  179.     RestoreA4();
  180.     return retCode;
  181. }